package spring.boot.adminx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import spring.boot.adminx.model.TCity;
import spring.boot.adminx.model.TDistricts;
import spring.boot.adminx.model.TProvince;
import spring.boot.adminx.service.TCityService;
import spring.boot.adminx.service.TDistrictsService;
import spring.boot.adminx.service.TProvinceService;

import java.util.List;

@RestController
public class TDistrictsController {

    @Autowired
    private TProvinceService tProvinceService;

    @Autowired
    private TCityService tCityService;

    @Autowired
    private TDistrictsService tDistrictsService;

    @GetMapping("province/list")
    public List<TProvince> provinceList(){
        return tProvinceService.list();
    }

    @GetMapping("city/list/{provinceId}")
    public List<TCity> provinceList(@PathVariable Integer provinceId){
        QueryWrapper<TCity> wrapper = new QueryWrapper<>();
        wrapper.eq("p_id",provinceId);
        return tCityService.list(wrapper);
    }

    @GetMapping("districts/list/{cityId}")
    public List<TDistricts> districtsList(@PathVariable Integer cityId){
        QueryWrapper<TDistricts> wrapper = new QueryWrapper<>();
        wrapper.eq("p_id",cityId);
        return tDistrictsService.list(wrapper);
    }
}
